<?php
/*
+--------------------------------------------------------------------------
|   phpBIZ v3.0  full version
|   ========================================
|   by taft@wjl.cn yejun@wjl.cn
|   http://www.phpbiz.cn http://www.wjl.cn
|   all rights reserved
+---------------------------------------------------------------------------
|
|   > 最后修改日期：2005-4-30 2006-2-8
|
+--------------------------------------------------------------------------
*/
!class_exists('Debug') && exit('Forbidden');
$gd = new ShopDetail;
class ShopDetail
{
	function ShopDetail()
	{// render it direct

	   global $DB,$BIZ,$INCOME;
		
	   define("PAGE_NUM",10);
	   
	   $id = intval( $INCOME['SHOP_ID'] );
	   $BIZ -> assign("shop_id",$id);
	   
	   //--------------------------------------
	   //check if exsit
	   //--------------------------------------
        $DB -> db_query( "SELECT count(*) as ct FROM biz_shop WHERE shop_id='".$id."'" );
		$row = $DB -> db_fetch_row();
		if( $row['ct'] !=1 ) $BIZ -> error( "查询错误","?act=Lst&code=s" );
	   //--------------------------------------
	   
	   
	   $DB -> db_query( "UPDATE biz_shop SET shop_visit_count = shop_visit_count +1 WHERE shop_id='".$id."'" );
	   //--------------------------------------
	   //shop info
	   //--------------------------------------

	   $DB -> db_query( "SELECT s.*,p.pic_name,b.seller_id,b.seller_logaccount,b.seller_logaccount,d.repute FROM biz_shop s LEFT JOIN biz_pic p  ON p.pic_id = s.shop_prime_picture_id LEFT JOIN biz_seller b ON b.seller_id = s.seller_id LEFT JOIN biz_seller_data d ON d.seller_id=s.seller_id WHERE s.shop_id ='".$id."' LIMIT 1" );
	   
	   $r_s = $DB -> db_fetch_row();
       
       $repute_array = array();

	   $sa = array( $r_s['shop_name'],$r_s['shop_location'],$r_s['shop_telephone'],$r_s['shop_catalog'],nl2br($r_s['shop_describle']),$r_s['seller_logaccount'],$BIZ->make_full_path($r_s['pic_name']),$r_s['seller_logaccount'],nl2br($r_s['shop_notice']),$r_s['repute'],repute_compute($r_s['repute']) );

	   $BIZ -> assign( "sa",$sa );
	   $seller_id = $r_s[seller_id];
	  
	   //--------------------------------------
	   //seller recommend goods
	   //--------------------------------------
       $DB -> db_query( "SELECT bg.*, bp.pic_name FROM biz_goods AS bg, biz_pic AS bp WHERE bp.pic_id=bg.goods_prime_picture_id AND bg.shop_id='".$id."' AND bg.goods_mark_sell='0' AND bg.goods_seller_recommend ='on' LIMIT 4" );

	   while( $g = $DB -> db_fetch_row() )
	   {
		   $tm = date("Y-m-d H:i",$g['goods_store_date']);
		   $thumb = $BIZ -> get_thumb($g['pic_name']);
		   $rg[] = array( $g['goods_id'],$g['goods_name'],$tm,$g['goods_price'],$thumb );
	   }
	   $pad = array("0","0");
	   $rg = array_pad($rg,4,$pad);
	   $BIZ -> assign("rg",$rg);	   

	   //---------------------------------------
	   // define cat info
	   //---------------------------------------
	   $DB -> db_query("SELECT * FROM biz_custom_catalog  WHERE shop_id =".$id);
	   while( $c = $DB -> db_fetch_row() )
	   {
		   $cat[] = array( $c[id],$c[title]);
	       $c[id]==$INCOME[ccid] && $BIZ -> assign("cn",$c[title]);
	   }
	   $BIZ -> assign("cat",$cat);

	   //--------------------------------------
	   // shop's adv info
	   //--------------------------------------
	   $DB -> db_query("SELECT * FROM biz_info WHERE info_owner_id =$seller_id AND info_type =".INFO_ADV." LIMIT 15");
	   while( $rs = $DB -> db_fetch_row() )
		{
		   $adv[] = array($rs['id'],$rs['info_title']);
		}
		$BIZ -> assign("adv",$adv);

	   //---------------------------------------
	   //share link 
	   //---------------------------------------
	   $DB -> db_query("SELECT * FROM biz_sharelink WHERE seller_id=".$seller_id);
	   while( $r_s = $DB -> db_fetch_row() )
	   { 
		   $sl[] = array($r_s[name],$r_s[url],$r_s[logo]);
	   }
	   $BIZ -> assign("sl",$sl);
	   //--------------------------------------
	   //goods belong it
	   //--------------------------------------

	    //---------------------------------------------------
		//判断排序条件
		//---------------------------------------------------
        switch($INCOME[FieldID])
		{
			case '1':
				$order = " ORDER BY `goods_store_date` DESC ";
			    break;
			case '2':
				$order = " ORDER BY `goods_store_date` ASC ";
				break;
			case '3':
				$order = " ORDER BY `goods_price` ASC ";
				break;
			case '4':
				$order = " ORDER BY `goods_price` DESC ";
			    break;
			case '5':
				$order = " ORDER BY `goods_visit_count` DESC ";
			    break;
			default:
				$order = " ORDER BY `goods_store_date` DESC ";
				break;
		}

		//ccat 
	    if($INCOME[ccid])
		{
			$condition = " AND goods_ccat_id =".intval($INCOME[ccid]);
			$ccstr = "&ccid=".intval($INCOME[ccid]); 
		}
	   
		//paging
		
		$start = $INCOME['st'] ? intval( $INCOME['st'] ) : 0;
		
		$DB -> db_query( "SELECT count(*) as count FROM biz_goods WHERE shop_id='".$id."' AND goods_mark_sell='0' ".$condition);
        
		$row_count = $DB -> db_fetch_row();

		if ($row_count['count'] < 1)
				$BIZ->error("暂无商品。","");
		
		$pages = $BIZ->build_pagelinks( array('TOTAL_POSS'  => $row_count['count'],
											   'PER_PAGE'    => PAGE_NUM,
											   'CUR_ST_VAL'  => $start,
											   'L_SINGLE'    => "一页",
											   'L_MULTI'     => "页：",
											   'BASE_URL'    => $this->base_url."?act=sd"."&SHOP_ID={$id}&FieldID={$INCOME['FieldID']}.$ccstr"
											   )
											);
		//--------------------------------------
	   
	   $DB  -> db_query( "SELECT bg.*, bp.pic_name FROM biz_goods AS bg, biz_pic AS bp WHERE bp.pic_id=bg.goods_prime_picture_id AND bg.shop_id='".$id."' AND bg.goods_mark_sell='0' ".$condition." ".$order." LIMIT $start,".PAGE_NUM );

	   while( $g = $DB -> db_fetch_row() )
	   {
		   $tm = date("Y-m-d H:i",$g['goods_store_date']);
		   $thumb = $BIZ -> get_thumb($g['pic_name']);
		   $ga[] = array( $g['goods_id'],$g['goods_name'],$tm,$g['goods_price'],$g['goods_visit_count'],$thumb );
	   }

	   $BIZ -> assign("glist",$ga);
	   $BIZ -> assign( "pages" , $pages);       
	   //--------------------------------------

	   $BIZ -> output("ShopDetail.tpl");

	}
}
?>